var wuKong = require ('./apps/wuKong/index');
var touTiao = require ('./apps/touTiao/index');
var {randomUtils, appUtils} = require ('./utils/index');

function vibrate () {
  while (true) {
    device.vibrate (2000);
    sleep (randomUtils.getRandom (1.5, 3, 1000));
  }
}

var apps = [wuKong, touTiao];
apps.forEach (function (app) {
  app.openCount = 0;
  app.maxOpenCount = 2;
  app.interval = 5 * 60;
});
while (true) {
  for (var index = 0; index < apps.length; index++) {
    var app = apps[index];
    var canRun = app.canRun ();
    app.main ();
    sleep (randomUtils.getRandom (5, 10, 1000));
    if (canRun) {
      appUtils.closeAll ();
    }
  }
  if (
    apps.every (function (app) {
      return !app.canRun ();
    })
  ) {
    break;
  }
}
vibrate ();
